var express = require('express');
var app = express();
var mainCtrl = require('./controllers/mainCtrl')
var StudentCtrl = require('./controllers/StudentCtrl')
var CourseCtrl = require('./controllers/CourseCtrl')
var ReportCtrl = require('./controllers/ReportCtrl')
var mongoose = require('mongoose');
var session = require('express-session')

mongoose.connect('mongodb://127.0.0.1/CourseSelectionSystem', function (err) {
    if (!err) {
        console.log('数据库连接成功')
    }else {
        console.log('数据库连接失败')
        return
    }
});

app.use(session({
    secret: '123',
    cookie: { maxAge: null },
    resave: false,
    saveUninitalized: true
}))

app.set('view engine', 'ejs');

app.get('/admin', mainCtrl.showAdminIndex )
app.get('/admin/showByStudent', mainCtrl.showAdminIndexByStudent)

app.get('/admin/student', StudentCtrl.showAdminStudentIndex )

app.get('/admin/student/import', StudentCtrl.showAdminStudentImport )
app.post('/admin/student/import', StudentCtrl.doAdminStudentImport )

app.get('/admin/course', CourseCtrl.showAdminCourseIndex )
app.get('/admin/course/import', CourseCtrl.showAdminCourseImport )
app.post('/admin/course/import', CourseCtrl.doAdminCourseImport )
app.get('/course', CourseCtrl.getAllCourseInfo); //获得所有课程数据数据
app.post('/course/:cid', CourseCtrl.setOneCourseInfo); //修改某个课程的数据
app.delete('/course', CourseCtrl.deleteCourse);   //删除某个或多个课程
app.get('/admin/course/add', CourseCtrl.showAdminCourseAdd);   //展示添加课程页面
app.post('/admin/course/add', CourseCtrl.doAdminCourseAdd);   //处理添加课程
app.propfind('/course/:cid', CourseCtrl.findCourseExist);  //校验某个课程是否存在

app.get('/admin/student/add', StudentCtrl.showAdminStudentAdd )
app.post('/admin/student/add', StudentCtrl.doAdminStudentAdd)

app.get('/admin/report', ReportCtrl.showAdminReportIndex )

app.get('/student', StudentCtrl.getAllStudentInfo); //获得学生管理页面的学生数据
app.delete('/student', StudentCtrl.deleteStudent);   //删除某个或多个学生
app.get('/student/download', StudentCtrl.downloadStudentInfo)  //下载学生信息表格

app.propfind('/student/:sid', StudentCtrl.findStudentExist);  //校验某个学生是否存在
app.post('/student/:sid', StudentCtrl.setOneStudentInfo);    //修改某个学生的信息
app.get('/myCourse', StudentCtrl.showMyCourse)  //展示我的课程页面

app.get('/login', mainCtrl.showLogin);
app.post('/login', mainCtrl.doLogin);
app.get('/', mainCtrl.showSignUpIndex);  //展示报名首页
// app.post('/', mainCtrl.doSignUpIndex);  //处理报名逻辑
app.get('/changePassword', mainCtrl.showChangePassword)  //展示修改密码页
app.post('/changePassword', mainCtrl.doChangePassword)   //提交密码表单
app.get('/exitLogin', mainCtrl.exitLogin)

app.get('/weatherCanSignUp', mainCtrl.weatherCanSignUp)

app.post('/selectCourse', mainCtrl.selectCourse)

app.use(express.static('public'));
app.listen(3000)